<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<form>

    服务器地址：
    <input type="plaintext" id="addr" value="114.116.243.181" />
    端口号：
    <input type="plaintext" id="port"  value="13999" />

    <br />

    货物名：
    <input type="plaintext" id="name" value="粉色安踏鞋"/>
    <br />
    货物ID：
    <input type="plaintext" id="id" value="001"/>
    <br />
    货物描述：
    <input type="plaintext" id="info" value="10-12岁小孩使用的粉色足球鞋"/>
    <br />
    货物数量：
    <input type="plaintext" id="num" value="20"/>
    <br />
	货物价格：
    <input type="plaintext" id="cost" value="12000"/>
    <br />
 </form>
<script type="text/javascript" src="message.js"></script>
<script type="text/javascript">
//    var type_list={MESSAGE:{},LOGIN:{}};
//    type_list["LOGIN"]={LOGIN_INFO:{},RETURN:{}};



    var isconnected = false;
    var wsock;

    var plainmsg = {"head":"","record":"","expand":""};
    plainmsg["head"]={"tag":"MESG","version":65537};
    var jsonstr = JSON.stringify(plainmsg);

    function mywebsockinit() {
        if (isconnected) {
            alert("已连接服务器！")
            return;
        }
        var netaddr=document.getElementById("addr");
        var netport=document.getElementById("port");

 //       wsock = new WebSocket('ws://192.168.159.135:12888', 'cube-wsport');
        wsock = new WebSocket('ws://'+netaddr.value+':'+netport.value, 'cube-wsport');

        wsock.onopen = function (e) {
            if (!isconnected) {
                isconnected = true;
                alert("连接成功！")
            }
            return;
        };
        wsock.onclose = function (e) {
        };
        wsock.onerror = function (e) {
        };
        wsock.onmessage = function (e) {
            var msg;
            msg = e.data;
            if (msg.replace(/(^s*)|(s*$)/g, "").length != 0) {
                alert(msg)
            }
        }
    }

    function myFunction() {
        if(!isconnected)
        {
            alert("连接未建立！")
            return;
        }

		var goods_info={"name":"","id":"","info":"","num":0,"cost":0};

		goods_info.name = document.getElementById("name").value;
		goods_info.id = document.getElementById("id").value;
		goods_info.info = document.getElementById("info").value;
		goods_info.num = document.getElementById("num").value;
		goods_info.cost = document.getElementById("cost").value;
        var msg = new Cube_msg("RECORD_DEFINE","GOODS_INFO");
        msg.addrecord(goods_info);
        wsock.send(msg.output())
    };
</script>
<button type="button" onclick="mywebsockinit()" id="connect">连接服务器</button>
<button type="button" onclick="myFunction()" id="sendmsg">发送货物信息</button>
</body>
</html>